package com.hs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.entity.dto.TeamEmp;
import com.hs.entity.dto.TeamType;
import com.hs.entity.dto.User;
import com.hs.mapper.TeamEmpMapper;
import com.hs.mapper.TeamTypeMapper;
import com.hs.service.TeamEmpService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeamEmpServiceImpl extends ServiceImpl<TeamEmpMapper, TeamEmp> implements TeamEmpService {


    @Resource
    private TeamEmpMapper teamEmpMapper;


    @Override
    public PageInfo<TeamEmp> selectTeamEmpList(Integer pageNum, String keywords) {
        PageHelper.startPage(pageNum,5);

        QueryWrapper<TeamEmp> queryWrapper = new QueryWrapper<>();

        if (keywords != null && !keywords.isEmpty()) {
            queryWrapper.like("team_user_name", keywords);  // 根据用户名进行模糊查询
        }

        List<TeamEmp> teamList = teamEmpMapper.selectListWithTeamName(queryWrapper);

        return new PageInfo<>(teamList);
    }

    @Override
    public List<TeamEmp> selectTeamEmpById(Integer id) {
        QueryWrapper<TeamEmp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("team_id", id);
        return teamEmpMapper.selectListWithTeamName(queryWrapper);
    }

    @Override
    public TeamEmp teamByUsername(String username) {
        QueryWrapper<TeamEmp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);  // 根据用户名查找

        return teamEmpMapper.selectOne(queryWrapper);
    }

    @Override
    public TeamEmp findTeamEmpByUsernameOrEmail(String username) {
        return this.query()
                .eq("username",username).or()
                .eq("email",username)
                .one();
    }

    @Override
    public PageInfo<TeamEmp> selectTeamEmpListByTeamId(Integer currentNum, String keywords, Integer teamId) {
        PageHelper.startPage(currentNum,5);

        QueryWrapper<TeamEmp> queryWrapper = new QueryWrapper<>();
        // 添加团队ID条件
        queryWrapper.eq("tt.team_id", teamId);
        if (keywords != null && !keywords.isEmpty()) {
            queryWrapper.like("team_user_name", keywords);  // 根据姓名进行模糊查询
        }

        List<TeamEmp> teamList = teamEmpMapper.selectListWithTeamName(queryWrapper);

        return new PageInfo<>(teamList);
    }


}
